<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of als_solve</title>
  <meta name="keywords" content="als_solve">
  <meta name="description" content="Computes an approximate rank-1 solution to the linear system">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html v1.5 &copy; 2003-2005 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../../m2html.css">
</head>
<body>
<a name="_top"></a>
<div><a href="../../index.html">Home</a> &gt;  <a href="#">tt2</a> &gt; <a href="index.html">solve</a> &gt; als_solve.m</div>

<!--<table width="100%"><tr><td align="left"><a href="../../index.html"><img alt="<" border="0" src="../../left.png">&nbsp;Master index</a></td>
<td align="right"><a href="index.html">Index for tt2/solve&nbsp;<img alt=">" border="0" src="../../right.png"></a></td></tr></table>-->

<h1>als_solve
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>Computes an approximate rank-1 solution to the linear system</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>function [x,y]=als_solve(mat,rhs,y,niter) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre class="comment">Computes an approximate rank-1 solution to the linear system
   [Y]=ALS_SOLVE(MAT,RHS,X) Computes (approximate) rank-1 solution to the
problems MAT*P = RHS, where A is a low-Kronecker rank matrix
P=X x Y, RHS is a low-Kronecker rank matrix
B is given as a two-2d cell array, the same is for X


 TT-Toolbox 2.2, 2009-2012

This is TT Toolbox, written by Ivan Oseledets et al.
Institute of Numerical Mathematics, Moscow, Russia
webpage: http://spring.inm.ras.ru/osel

For all questions, bugs and suggestions please mail
ivan.oseledets@gmail.com
---------------------------</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="../../tt2/@tt_matrix/size.html" class="code" title="function [sz] = size(tt)">size</a>	Mode sizes of the TT-matrix</li><li><a href="../../tt2/@tt_tensor/reshape.html" class="code" title="function [tt2]=reshape(tt1,sz,eps, rl, rr)">reshape</a>	Reshape of the TT-tensor</li><li><a href="../../tt2/@tt_tensor/size.html" class="code" title="function [sz] = size(tt,dim)">size</a>	Mode sizes of the TT-tensor</li></ul>
This function is called by:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="als_solve2.html" class="code" title="function [sol1]=als_solve2(mat,rhs,eps,sol,niter)">als_solve2</a>	A greedy method to solve a linear system</li></ul>
<!-- crossreference -->



<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [x,y]=als_solve(mat,rhs,y,niter)</a>
0002 <span class="comment">%Computes an approximate rank-1 solution to the linear system</span>
0003 <span class="comment">%   [Y]=ALS_SOLVE(MAT,RHS,X) Computes (approximate) rank-1 solution to the</span>
0004 <span class="comment">%problems MAT*P = RHS, where A is a low-Kronecker rank matrix</span>
0005 <span class="comment">%P=X x Y, RHS is a low-Kronecker rank matrix</span>
0006 <span class="comment">%B is given as a two-2d cell array, the same is for X</span>
0007 <span class="comment">%</span>
0008 <span class="comment">%</span>
0009 <span class="comment">% TT-Toolbox 2.2, 2009-2012</span>
0010 <span class="comment">%</span>
0011 <span class="comment">%This is TT Toolbox, written by Ivan Oseledets et al.</span>
0012 <span class="comment">%Institute of Numerical Mathematics, Moscow, Russia</span>
0013 <span class="comment">%webpage: http://spring.inm.ras.ru/osel</span>
0014 <span class="comment">%</span>
0015 <span class="comment">%For all questions, bugs and suggestions please mail</span>
0016 <span class="comment">%ivan.oseledets@gmail.com</span>
0017 <span class="comment">%---------------------------</span>
0018 
0019 a=mat{1}; <span class="comment">%The first cell</span>
0020 b=mat{2}; 
0021 R=<a href="../../tt2/@tt_matrix/size.html" class="code" title="function [sz] = size(tt)">size</a>(a,3); <span class="comment">%The rank</span>
0022 n=<a href="../../tt2/@tt_matrix/size.html" class="code" title="function [sz] = size(tt)">size</a>(a,1);
0023 m=<a href="../../tt2/@tt_matrix/size.html" class="code" title="function [sz] = size(tt)">size</a>(b,1);
0024 a1=permute(a,[1,3,2]); a1=<a href="../../tt2/@tt_tensor/reshape.html" class="code" title="function [tt2]=reshape(tt1,sz,eps, rl, rr)">reshape</a>(a1,[n*R,n]);
0025 b1=permute(b,[1,3,2]); b1=<a href="../../tt2/@tt_tensor/reshape.html" class="code" title="function [tt2]=reshape(tt1,sz,eps, rl, rr)">reshape</a>(b1,[m*R,m]);
0026 rhs1=<a href="../../tt2/@tt_tensor/reshape.html" class="code" title="function [tt2]=reshape(tt1,sz,eps, rl, rr)">reshape</a>(rhs,n,m);
0027 <span class="keyword">if</span> ( nargin &lt; 5 )
0028    niter=10;
0029 <span class="keyword">end</span>
0030 
0031 
0032 <span class="keyword">for</span> i=1:niter
0033     <span class="comment">%fprintf('i=%d \n',i);</span>
0034     <span class="comment">%at=a1*x;</span>
0035     <span class="comment">%bt=b1*y;</span>
0036     <span class="comment">%Iterate over x</span>
0037     bt=b1*y; <span class="comment">%bt is n*R</span>
0038     <span class="comment">%bt is n*R, scalar product of</span>
0039     bt1=<a href="../../tt2/@tt_tensor/reshape.html" class="code" title="function [tt2]=reshape(tt1,sz,eps, rl, rr)">reshape</a>(bt,[m,R]);
0040     p=bt1'*bt1; <span class="comment">%p matrix is ready</span>
0041     <span class="comment">%Compute the local matrix sum_{a,b} p_{ab} A^{\top}_b A_a,</span>
0042     <span class="comment">%it is A(k,i,b)*A(k,j,a)*p(a,b)</span>
0043     a2=<a href="../../tt2/@tt_tensor/reshape.html" class="code" title="function [tt2]=reshape(tt1,sz,eps, rl, rr)">reshape</a>(a,[n*n,R]); a2=a2*p; <span class="comment">%a2 is (k,j,b), sum over (k,b) with (k,i,b)</span>
0044     a3=<a href="../../tt2/@tt_tensor/reshape.html" class="code" title="function [tt2]=reshape(tt1,sz,eps, rl, rr)">reshape</a>(a,[n,n,R]); a3=permute(a3,[2,1,3]); a3=<a href="../../tt2/@tt_tensor/reshape.html" class="code" title="function [tt2]=reshape(tt1,sz,eps, rl, rr)">reshape</a>(a3,[n,n*R]);
0045     a2=<a href="../../tt2/@tt_tensor/reshape.html" class="code" title="function [tt2]=reshape(tt1,sz,eps, rl, rr)">reshape</a>(a2,[n,n,R]); a2=permute(a2,[2,1,3]); a2=<a href="../../tt2/@tt_tensor/reshape.html" class="code" title="function [tt2]=reshape(tt1,sz,eps, rl, rr)">reshape</a>(a2,[n,n*R]);
0046     loc_mat=a3*a2'; <span class="comment">%Should be valid even for complex numbers</span>
0047     <span class="comment">%For the full right hand side</span>
0048     <span class="comment">%The sum is rhs(i,j)*A(i,k,b)*B(j,b)</span>
0049     <span class="comment">%first sum over j</span>
0050     rhs=rhs1*bt1; <span class="comment">%rhs is i x b, sum over (i,b)</span>
0051     rhs=<a href="../../tt2/@tt_tensor/reshape.html" class="code" title="function [tt2]=reshape(tt1,sz,eps, rl, rr)">reshape</a>(rhs,[1,n*R]);
0052     rhs=rhs*a1;
0053     rhs=rhs';
0054     
0055     x= loc_mat \ rhs;
0056     <span class="comment">%cond(loc_mat)</span>
0057     <span class="comment">%Iterate over y</span>
0058     at=a1*x;
0059     at1=<a href="../../tt2/@tt_tensor/reshape.html" class="code" title="function [tt2]=reshape(tt1,sz,eps, rl, rr)">reshape</a>(at,[n,R]);
0060     <span class="comment">%bt is n*R*n, scalar product of</span>
0061     p=at1'*at1; <span class="comment">%p matrix is ready</span>
0062     <span class="comment">%Compute the local matrix sum_{a,b} p_{ab} A^{\top}_b A_a,</span>
0063     <span class="comment">%or the summation: \sum_{a,b,k} p(a,b) A(i,k,a)*A(j,k,b)</span>
0064     b2=<a href="../../tt2/@tt_tensor/reshape.html" class="code" title="function [tt2]=reshape(tt1,sz,eps, rl, rr)">reshape</a>(b,[m*m,R]); b2=b2*p; <span class="comment">%a2 is (k,j,b), sum over (k,b) with (k,i,b)</span>
0065     b3=<a href="../../tt2/@tt_tensor/reshape.html" class="code" title="function [tt2]=reshape(tt1,sz,eps, rl, rr)">reshape</a>(b,[m,m,R]); b3=permute(b3,[2,1,3]); b3=<a href="../../tt2/@tt_tensor/reshape.html" class="code" title="function [tt2]=reshape(tt1,sz,eps, rl, rr)">reshape</a>(b3,[m,m*R]);
0066     b2=<a href="../../tt2/@tt_tensor/reshape.html" class="code" title="function [tt2]=reshape(tt1,sz,eps, rl, rr)">reshape</a>(b2,[m,m,R]); b2=permute(b2,[2,1,3]); b2=<a href="../../tt2/@tt_tensor/reshape.html" class="code" title="function [tt2]=reshape(tt1,sz,eps, rl, rr)">reshape</a>(b2,[m,m*R]);
0067     loc_mat=b3*b2'; <span class="comment">%Should be valid even for complex numbers</span>
0068         <span class="comment">%For the full right hand side</span>
0069     <span class="comment">%The sum is rhs(i,j)*A(i,k,b)*B(j,b)</span>
0070     <span class="comment">%first sum over j</span>
0071     rhs=rhs1'*at1; <span class="comment">%rhs is i x b, sum over (i,b)</span>
0072     rhs=<a href="../../tt2/@tt_tensor/reshape.html" class="code" title="function [tt2]=reshape(tt1,sz,eps, rl, rr)">reshape</a>(rhs,[1,m*R]);
0073     rhs=rhs*b1;
0074     rhs=rhs';
0075 
0076     y= loc_mat \ rhs;
0077     
0078     <span class="comment">%    norm(tt_matrix(mat)*kron(y,x)-rhs1(:))</span>
0079     <span class="comment">%keyboard;</span>
0080     <span class="comment">%norm(tt_matrix(mat)*kron(tt_matrix(x,1e-10),tt_matrix(y,1e-10))-tt_mat</span>
0081     <span class="comment">%rix(rhs1))</span>
0082 <span class="keyword">end</span>
0083 <span class="keyword">return</span></pre></div>
<hr><address>Generated on Wed 08-Feb-2012 18:20:24 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" title="Matlab Documentation in HTML">m2html</a></strong> &copy; 2005</address>
</body>
</html>